package com.congee02.modelshellmvn.adapter;

import com.alibaba.fastjson.JSON;
import com.congee02.modelshellmvn.anno.RecordAdapter;
import com.congee02.modelshellmvn.entity.plate.PlateRecognitionRecordDeprecated;
import com.congee02.modelshellmvn.entity.plate.vo.PlateRecognitionResult;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;

@Component
public class PlateRecognitionRecordAdapter implements RecordAdapter<PlateRecognitionResult, PlateRecognitionRecordDeprecated> {
    @Override
    public PlateRecognitionRecordDeprecated adapt(PlateRecognitionResult plateRecognitionResult) {
        PlateRecognitionRecordDeprecated record = new PlateRecognitionRecordDeprecated();
        BeanUtils.copyProperties(
                plateRecognitionResult, record, "rect"
        );
        record.setRect(
                JSON.toJSONString(
                        plateRecognitionResult.getRect()
                )
        );
        record.setTime(
                new Timestamp(
                        System.currentTimeMillis()
                )
        );
        return record;
    }
}
